#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from PIL import Image
from student import Student
from student import MiniStu
from student import NoStu
import types
from student import Screen
from types import MethodType
im = Image.open("C:\\Users\\Administrator\\Desktop\\getheadimg.jpg")
print(im.size, im.mode)

dean = Student("dean", 24)
# dean.setName("1111")
# 实例的属性比类的属性有更高的优先级
dean.school = "dean学校"
del dean.school  # 删除属性
print(dean.school)
dean.name = "1"
print(dean.name)
# dean.printStu()
# print(dean._Student__name)

miniDean = MiniStu("minidean", 24, "男")

# miniDean.printStu()


# 多态演示
def show(student):
    student.printStu()


show(dean)
show(miniDean)

# 动态语言非继承也可调用
show(NoStu())

print(
    type(dean), type(miniDean), type(NoStu()),
    type(show) == types.FunctionType)
# 对象属性操作
print(dir(dean), len(dean), dean)
print(hasattr(dean, "age"), hasattr(dean, "printStu"))
print(getattr(dean, "age", None))
setattr(dean, "age", 10)
print(getattr(dean, "age", None))


# 实例动态绑定方法  类动态绑定方法
def addTimes(self, newName):
    # return self.getName() + " " + newName + " now"  #未使用property
    return self.name + " " + newName + " now"


dean.addTimes = addTimes
print(dean.addTimes(dean, "111"))  # 必须将self做参数传进去，看不出太大差别

dean.addTimes = MethodType(addTimes, dean)
print(dean.addTimes("111"))
# property练习
screen = Screen()
screen.width = 1920
screen.height = 1080
print(screen.resolution)
